//#ifndef compdict_js
//#define compdict_js 1

// Hashtable dictionary used by compressor
function CompressDictionary () {
  this.hashtable = {};
  this.nextcode = 0;

  // Populate table with all possible character codes.
  for(var i = 0; i < 256; ++i) {
    var str = String.fromCharCode(i);
    this.hashtable[str] = this.nextcode++;
  }  
}

CompressDictionary.prototype = {

  Exists : function(str) {
    return (this.hashtable.hasOwnProperty(str));
  },

  Insert : function(str) {
    var numBits = this.ValSizeInBits();
    this.hashtable[str] = this.nextcode++;
    return numBits;
  },

  Lookup : function(str) {
    return (this.hashtable[str]);
  },

  ValSizeInBits : function() {
    // How many bits are we currently using to represent values?
    var log2 = Math.log(this.nextcode + 1)/Math.LN2;
    return Math.ceil(log2);
  }
  
};

//#endif

